using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using OpenTK.Math;
using Dogfight2008.Common;
using NUnit.Framework.SyntaxHelpers;

namespace Dogfight2008.Tests
{
  [TestFixture]
  public class PlaneFixture
  {
    [Test]
    public void Construct()
    {
      Plane plane = new Plane(new Vector2(0,0), 0, 5);
    }

    [Test]
    public void InitialState()
    {
      Plane plane = new Plane(Calc.v(0, 0), 0, 5);
      Assert.AreEqual(PlaneState.Flying, plane.State);
    }

    [Test]
    public void StartFalling()
    {
      Plane plane = new Plane(Calc.v(0, 0), 0, 5);
      plane.StartFalling();
      Assert.AreEqual(PlaneState.Falling, plane.State);
    }

    [Test]
    public void RightGoingPlane()
    {
      Plane plane = new Plane(Calc.v(0, 0), 0, 10);
      plane.Tick(1000);
      Assert.That(plane.X, Is.GreaterThan(0));
    }

    [Test]
    public void LeftGoingPlane()
    {
      Plane plane = new Plane(Calc.v(0, 0), Calc.DegreesToRadians(180), 10);
      plane.Tick(1000);
      Assert.That(plane.X, Is.LessThan(0));
    }

    [Test, Ignore]
    public void Fire() {
      Plane plane = APlane();
      Assert.IsNotNull(plane.Fire());
    }

    [Test,Ignore]
    public void FireTwiceFastNotPossible()
    {
      Plane plane = APlane();
      plane.Fire();
      Assert.IsNull(plane.Fire());
    }

    [Test, Ignore]
    public void FireTwiceWithBigElapsedTimeOK()
    {
      Plane plane = APlane();
      plane.Fire();
      plane.Tick(20000);
      Assert.IsNotNull(plane.Fire());
    }

    private static Plane APlane()
    {
      Plane plane = new Plane(new Vector2(0, 3), 0, 20);
      return plane;
    }

    [Test, Ignore]
    public void FireTwiceWithRightDelayOK()
    {
      Plane plane = APlane();
      double fireDelay = Plane.ReloadTimeMs;
      plane.Fire();
      plane.Tick(fireDelay);
      Assert.IsNotNull(plane.Fire());
    }

    [Test, Ignore]
    public void FireTwiceWithALittleTooShortDelayWillNotWork()
    {
      Plane plane = APlane();
      double fireDelay = Plane.ReloadTimeMs;
      plane.Fire();
      plane.Tick(fireDelay-1);
      Assert.IsNull(plane.Fire());
    }

    [Test, Ignore]
    public void ShotGetsCorrectProperties()
    {
      double x = 50;
      double y = 60;
      double angle = 70;
      double speed = 80;
      Plane plane = new Plane(new Vector2((float)x, (float)y), angle, speed);
      Shot shot = plane.Fire();
      Assert.AreEqual(plane.X, shot.Position.X, 1);
      Assert.AreEqual(plane.Y, shot.Position.Y, 1);
      Assert.AreEqual(plane.Angle, shot.Angle, 1);
      //Assert.AreEqual(speed, shot.Speed);
    }
  }
}
